<template>
  <div>
    <van-field name="uploader" label="文件上传" :required="element.required" :readonly="element.readonly" :disabled="element.disabled">
      <template #input>
        <van-uploader :disabled="element.disabled" v-model="uploader" :after-read="afterRead" multiple :max-count="2" @oversize="onOversize" />
      </template>
    </van-field>
  </div>
</template>

<script>
export default {
  name: 'uploader',
  inject: [
    'element'
  ],
  data() {
    return {
      uploader: []
    }
  },
  methods: {
    afterRead(file) {
      // 此时可以自行将文件上传至服务器
      // console.log(file);
    },
    onOversize(file) {
      // console.log(file);
      Toast('文件大小不能超过 500kb')
    }
  }
}
</script>

<style lang="scss" scoped>
.van-cell::after {
  display: block;
}
</style>